import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class CDshop {
    static ArrayList<CD> listsell;
    static ArrayList<CD> listlend;

    CDshop(){
        listsell=new ArrayList<>();
        listlend=new ArrayList<>();
        for(int i=1; i<=11; i++){
            CD cd1=new CD(10);
            CD cd2=new CD(1);
            listsell.add(cd1);
            listlend.add(cd2);
        }


    }
    synchronized public void full(){
        for(int i=1; i<=10; i++){
            listsell.get(i).number=10;
        }
        System.out.println(new Date()+Thread.currentThread().getName()+"补货完毕");
    }

    synchronized public boolean sell(int id, int num){
        if(listsell.get(id).number>=num){
            listsell.get(id).number-=num;
            System.out.println(new Date()+Thread.currentThread().getName()+"CD_id_"+id+"销售了"+num+"剩余"+listsell.get(id).number);
            return true;
        }
        else{
            System.out.println(new Date()+Thread.currentThread().getName()+"CD_id_"+id+"库存不足");
            return false;
        }
    }

    synchronized public boolean lend(int id){
        if(listlend.get(id).number>=1){
            listlend.get(id).number--;
            System.out.println(new Date()+Thread.currentThread().getName()+"CD_lend_id_"+id+"借出了");
            return true;
        }
        else{
            System.out.println(new Date()+Thread.currentThread().getName()+"CD_lend_id_"+id+"库存不足");
            return false;
        }
    }
    synchronized public void retrn(int id){
        listlend.get(id).number++;
        System.out.println(new Date()+Thread.currentThread().getName()+"CD_lend_id_"+id+"归还了");
    }
}
